<template>
	<view>
		<view class="main-item flex" @tap="Survey">
			<image :src="imgurl+'diaocha.png'"></image>
			<view class="right">
				<view class="text-one">调查</view>
				<view>强大逻辑,发掘事实</view>
			</view>
		</view>
		<view class="main-item flex" @tap="Form">
			<image :src="imgurl+'biaodan.png'"></image>
			<view class="right">
				<view class="text-one">表单</view>
				<view>信息登记,活动报名</view>
			</view>
		</view>
		<view class="main-item flex" @tap="Vote">
			<image :src="imgurl+'toupiao.png'"></image>
			<view class="right">
				<view class="text-one">投票</view>
				<view>信息测定,图文投票</view>
			</view>
		</view>
		<uni-popup animation="ture" maskClick='false' ref="popup" type="bottom">
			<uni-list>
				<uni-list-item v-for="(item, index) in moList" :key="item.id" :title="item.moname" :show-badge="true" badge-text="确定" @tap="checkMo(item.moid)"></uni-list-item>
			</uni-list>
		</uni-popup>
	</view>
</template>

<script>
	import app from "../../App.vue"
	import api from "@/common/api.js"
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue'
	import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
	import uniList from "@/components/uni-list/uni-list.vue"
	import uniListItem from "@/components/uni-list-item/uni-list-item.vue"
	export default {
		data() {
			return {
				imgurl: "",
				wenid: '',
				fromUrl: '',
				moList: [],
				popupStatus: false
			};
		},
		components: {
			uniPopup,
			uniPopupMessage,
			uniPopupDialog,
			uniList,
			uniListItem
		},
		methods: {
			//调查
			Survey() {
				if (this.wenid != '' && this.fromUrl == 'model') {
					this.popupStatus = true
					this.getMoList(1)
				} else {
					app.globalData.typewj = 1
					uni.navigateTo({
						url: "../createSurvey/createSurvey"
					})
				}
			},
			Form() {
				if (this.wenid != '' && this.fromUrl == 'model') {
					this.popupStatus = true
					this.getMoList(2)
				} else {
					app.globalData.typewj = 2
					uni.navigateTo({
						url: "../createForm/createform/createform"
					})
				}
			},
			Vote() {
				if (this.wenid != '' && this.fromUrl == 'model') {
					this.popupStatus = true
					this.getMoList(3)
				} else {
					app.globalData.typewj = 3
					uni.navigateTo({
						url: "../createVote/createvote/createvote"
					})
				}
			},
			// 模板List
			getMoList(type) {
				api.look({
					api: 'wenmo',
					lei: type
				}).then(res => {
					if (res.code == 200) {
						(res.date || []).map((v, k)=>{
							this.moList.push(v)
						})
						// this.moList = res.date;
						this.moList.unshift({
							moid: 0,
							moname: "默认模板"
						})
						if(this.popupStatus){
							this.$refs.popup.open()
							this.popupStatus = false
						}
					} else {
						uni.showToast({
							title: '目前没有模板类型，请到后台新增',
							icon: 'none',
							success: () => {
							}
						})
					}
					console.log('moList',this.moList)
				}).catch(err => {
					console.log(err)
				})
			},
			// 选择模板
			checkMo(moid) {
				this.$refs.popup.open()
				api.look({
					api: 'wendaomo',
					wenid: this.wenid,
					moid: moid
				}).then(res => {
					if(res.code == 200) {
						uni.showToast({
							title: '模板设置成功',
							icon: 'success',
							success: () => {
								setTimeout(() => {
									uni.reLaunch({
										url: '../index/index'
									})
								}, 2000)
							}
						})
					} else {
						uni.showToast({
							title: '模板设置失败',
							icon: 'none',
							duration: 2000
						})
					}
				}).catch(err => {
					console.log(err)
				})
			},
		},
		onShareAppMessage(options) {
			let shareObj = {
				success: (res) => {
					if (res.errMsg == 'shareAppMessage:ok') {
						uni.showToast({
							title: '分享成功',
							icon: 'success',
							duration: 1500
						})
					}
				},
				fail: () => {
					if (res.errMsg == 'shareAppMessage:fail cancel') {
						uni.showToast({
							title: '取消分享',
							icon: 'none',
							duration: 2000
						})
					} else if (res.errMsg == 'shareAppMessage:fail') {
						// 转发失败，其中 detail message 为详细失败信息
					}
				},
				complete: () => {
					// 转发结束之后的回调（转发成不成功都会执行）
				}
			}
		},
		onLoad(options) {
			this.imgurl = app.globalData.imgurl
			console.log(options)
			if (options.wenid) {
				this.wenid = options.wenid
				this.fromUrl = options.fromUrl
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F0F0F0
	}

	.moList {
		width: 100%;
		height: 100vh;
		padding: 30rpx;

	}

	.main-item {
		width: 690rpx;
		height: 200rpx;
		margin: 20rpx auto;
		background: rgba(255, 255, 255, 1);
		box-shadow: 0rpx 5rpx 10rpx 0rpx rgba(240, 240, 240, 1);
		border-radius: 5rpx;

		image {
			width: 60rpx;
			height: 60rpx;
			margin: 0 30rpx 0 40rpx;
		}

		.right {
			display: flex;
			flex-direction: column;
			color: #999;
			font-size: 20rpx;

			.text-one {
				color: #333;
				font-size: 36rpx;
				font-weight: bold;
			}
		}
	}
</style>
